package com.ruoyi.zq.service.impl;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.zq.mapper.EntryBlankMapper;
import com.ruoyi.common.zq.mapper.ZqVolunteerActivityMapper;
import com.ruoyi.system.mapper.SysRoleMapper;
import com.ruoyi.system.service.ISysUserService;
import com.ruoyi.common.zq.domin.dto.IndexDTO;
import com.ruoyi.common.zq.domin.vo.ActivityVO;
import com.ruoyi.zq.service.ZqIndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * TODO
 *
 * @Author: LoneyFeather
 * @Date: Created in 10:22 2022/2/10
 */
@Service
public class ZqIndexServiceImpl implements ZqIndexService {

    @Autowired
    private ISysUserService sysUserService;
    @Autowired
    private SysRoleMapper roleMapper;

    @Autowired
    private ZqVolunteerActivityMapper activityMapper;

    @Autowired
    private EntryBlankMapper entryBlankMapper;

    @Override
    public Map getBasicData(Long userId) {
        Map<String,Object> map =new HashMap<>();
        SysUser user = sysUserService.selectUserById(userId);

        Boolean isStudent = isStudent(userId);

        DecimalFormat df = new DecimalFormat("###.0");

        map.put("user",user);
        map.put("agvGrade",Float.valueOf(df.format(entryBlankMapper.agvGrade(userId))));
        map.put("isStudent",isStudent);
        return map;
    }


    /**
     * 判断是否是学生
     * @param userId
     * @return
     */
    @Override
    public Boolean isStudent(Long userId) {
        Boolean isStudent = false;
        List<Long> roleIds = roleMapper.selectRoleListByUserId(userId);
        isStudent = roleIds.contains(3L);
        return isStudent;
    }

    @Override
    public List<ActivityVO> activityList(IndexDTO indexDTO) {
        Boolean isStudent = isStudent(SecurityUtils.getUserId());
        //进行判断是相应的什么角色
        if(isStudent) {
            return activityMapper.listActivity(indexDTO);
        }else {
            return activityMapper.listActivityByadmin(indexDTO);
        }
    }
}
